<!--
 * @Author       : xiaowu wwl093000@163.com
 * @Date         : 2023-04-19 17:45:34
 * @LastEditTime : 2023-05-06 14:18:37
 * @LastEditors  : xiaowu wwl093000@163.com
 * @FilePath     : /erp-admin-ui/src/views/workorder/list/index.vue
 * @Description  : -
-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="工单编号" prop="id">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入工单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="问题标题" prop="subject">
        <el-input
          v-model="queryParams.subject"
          placeholder="请输入问题标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="问题分类" prop="type">
        <el-select v-model="queryParams.type" clearable>
          <el-option
            v-for="dict in dict.type.erp_work_order_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value*1"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" clearable>
          <el-option
            v-for="dict in statusList"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value*1"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="工单编号" align="center" prop="id" />
      <el-table-column show-overflow-tooltip label="问题标题" align="center" prop="subject" />
      <el-table-column label="问题分类" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.erp_work_order_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == '0'" type="info">待处理</el-tag>
          <el-tag v-if="scope.row.status == '1'" type="success">处理中</el-tag>
          <el-tag v-if="scope.row.status == '2'">处理完成</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-crop"
            @click="handleView(scope.row)"
          >查看</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
          >确认解决</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getWorkOrderList } from "@/api/workorder/index";
import store from '@/store';
export default {
  name: "WorkOrderList",
  dicts: ['erp_work_order_type'],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采集商品表格数据
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        subject: undefined,
        type: undefined,
        status: undefined,
        id: undefined
      },
      statusList: [
        {
          label: '待处理',
          value: '0'
        },
        {
          label: '处理中',
          value: '1'
        },
        {
          label: '处理完成',
          value: '2'
        }
      ]
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询采集商品列表 */
    getList() {
      this.loading = true;
      // this.queryParams.createBy = store.getters.userId;
      getWorkOrderList(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 查看
    handleView(row) {
      this.$router.push(`/workorder/details/` + row.id)
    }
  }
};
</script>
